package com.lzw.common.controller;

import com.lzw.common.tool.StringTool;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 基础控制器，系统所有控制器都会继承该控制器
 * Created by 林志伟 on 2017/5/11.
 */
@Controller
public class BaseController {

    @Autowired
    protected HttpServletRequest request;

    @Autowired
    protected HttpServletResponse response;

    protected final Logger  logger = Logger.getLogger(this.getClass());
    public BaseController(){

    }

    /**
     * 获取类名
     * @return
     */
    public String getClassName(){
        return  StringTool.lowerStringFirst(this.getClass().getSimpleName());
    }



    /**
     * 获取模板名称
     * @return
     */
    public String getTemplateName(){
        String methodName=new Throwable().getStackTrace()[1].getMethodName();
        String controlerName=this.formatControllerName(getClassName());
        String template=controlerName+"/"+methodName;
        return template;
    }

    /**
     * 格式化控制器名称
     * @param controlerName
     * @return
     */
    private String formatControllerName(String controlerName){
        return  controlerName.replaceAll("Controller","");
    }
}
